package leetcode2;

public class Day6 {

    public static void main(String[] args) {
        int[] a = {1,5,11,5};
    }
    //416.割分等和子集
    public boolean canPartition(int[] nums) {
        int n = nums.length;
        int sum = 0;
        for(int i=0;i<n;i++) {
            sum += nums[i];
        }
        if(sum % 2 !=0) return false;
        sum /= 2;
        boolean[][] dp = new boolean[n+1][sum+1];
        for(int i=0;i<=n;i++) dp[i][0]=true;
        for(int i=1;i<=n;i++) {
            for(int j=1;j<=sum;j++) {
                dp[i][j]=dp[i-1][j] || (j >= nums[i-1] && dp[i-1][j-nums[i-1]]);
            }
        }
        return dp[n][sum];
    }
}
